<?php
$_order       = $this->getOrder();
$_currentFlag = $this->getCurrentFlag();
?>

<div id="orderflag<?php echo $_order->getId(); ?>" onclick="javascript: openFlagDialog(<?php echo $_order->getId(); ?>, '<?php echo $_order->getIncrementId(); ?>');">
    <div>
        <?php if ($_currentFlag): ?>
            <img src="<?php echo $_currentFlag->getUrl(); ?>" id="flagimg<?php echo $_order->getId(); ?>" title="<?php echo $_currentFlag->getComment(); ?>" alt="<?php echo $_currentFlag->getComment(); ?>" border="0" />
        <?php else: ?>
            <img src="<?php echo $this->getEmptyFlagUrl(); ?>" id="flagimg<?php echo $_order->getId(); ?>" title="" alt="" border="0" />
        <?php endif; ?>
    </div>
    <input type="hidden" id="orderflag-<?php echo $_order->getId(); ?>-flagid" name="orderflag-<?php echo $_order->getId(); ?>-flagid" value="<?php if ($_currentFlag): echo $_currentFlag->getId(); endif; ?>" />
</div>

<div id="flaglist<?php echo $_order->getId(); ?>" style="display: none;">
    <div style="margin-top: 8px; margin-bottom: 8px;">
        <?php echo $this->__('Enter/modify comment for the flag you want to assign, and click "Set" button.'); ?>
    </div>
    <table>
        <tr>
            <td></td>
            <td><strong><?php echo $this->__('NO FLAG'); ?></strong></td>
            <td>
                <button onclick="javascript: setOrderFlag('<?php echo $this->getSetFlagUrl(); ?>', <?php echo $_order->getId(); ?>, 0, '<?php echo $this->getEmptyFlagUrl(); ?>');" class="scalable go" type="button"><span><?php echo $this->__('Set'); ?></span></button>
            </td>
        </tr>
        <?php foreach ($this->getFlagCollection() as $flag): ?>
        <tr><td colspan="3" height="5"></td></tr>
        <tr>
            <td <?php /* if ($_currentFlag && $flag->getId() == $_currentFlag->getId()): ?>style="background-color: #f98721;"<?php endif; */ ?>>
                <img src="<?php echo $flag->getUrl(); ?>" alt="" border="0" id="flagselect-img-<?php echo $_order->getId(); ?>-<?php echo $flag->getId(); ?>" />
            </td>
            <td><input type="text" value="<?php /* if ($_currentFlag && $flag->getId() == $_currentFlag->getId()): ?><?php echo $_currentFlag->getComment(); ?><?php else: */ ?><?php echo $flag->getComment(); ?><?php /* endif; */ ?>" id="flagselect-comment-<?php echo $_order->getId(); ?>-<?php echo $flag->getId(); ?>" class="input-text" style="width: 230px;" /></td>
            <td>
                <button onclick="javascript: setOrderFlag('<?php echo $this->getSetFlagUrl(); ?>', <?php echo $_order->getId(); ?>, <?php echo $flag->getId(); ?>);" class="scalable go" type="button"><span><?php echo $this->__('Set'); ?></span></button>
            </td>
        </tr>
        <?php endforeach; ?>
    </table>
</div>